// while循环
/*
    例如求1～10的和
*/
let num = 1;
let sum = 0;
while (num <= 10) {
  sum += num;
  //步进条件
  num++;
}
console.log("1~10的和为", sum);

//for循环
/*
    例如求1～100的和
*/

let sum1 = 0;
for (let i = 0; i <= 100; i++) {
  sum1 += i;
}
console.log("1~100的和为", sum1);

//for...in
/*
    常用于遍历对象，
    注意:对象的键是字符串
*/
let obj = { a: 100, b: 200, c: 300 };
for (let key in obj) {
  console.log(`${key}的值为${obj[key]}`);
}

//for...of
// 迭代数组
let arr = [0, 1, 2, 3];
for (let item of arr) {
  console.log(item);
}

//迭代Map
let myMap = new Map();
myMap.set(1, "hello").set("a", 100);
for (let item of myMap) {
  console.log(item);
}
